<?php

namespace app\api\controller;

use app\model\Types as TypesModel;
use think\Db;
use think\facade\Log;
use think\facade\Request;

/**
 * @title   产品类别接口
 * @desc    产品类别接口
 * Class Link
 * @package app\api\controller
 */

class Link extends Common
{
    /**
     * @title 产品类别接口
     * @desc  产品类别接口
     *
     * @param int $title
     * @param int $limit 10
     *
     * @return Array $list 产品类别列表
     */
    public function lists()
    {
        // try {
        //     $msg = $this->Auth();
        //     if (!$msg) {
        $limit = $this->request->param('limit');
        $pid = $this->request->param('pid');
        if (!$limit) {
            $limit = 10;
        }
        if (!$pid) {
            $pid = 0;
        }
        $list = TypesModel::where('parentid', $pid)
            ->field(['id', 'title' . 'parentid', 'path'])
            ->order('id desc')
            ->paginate($limit);
        return $this->jsonPage($list->total(), $list->toArray()['data']);
    }

    /**
     * 单个类别信息
     * @return string
     */
    public function info()
    {
        // if ($this->request->isPost()) {
        //     $msg = $this->Auth();
        //     if (!$msg) {
        $id = $this->request->param('id');
        $limit = $this->request->param('limit');
        if ($id != '') {
            $map[] = ['id', '=', $id];
        }
        if (!$limit) {
            $limit = 10;
        }
        $list = TypesModel::where($map)
            ->field(['id', 'title' . 'parentid', 'path'])
            ->order('id desc')
            ->paginate($limit);
        return $this->jsonPage($list->total(), $list->toArray()['data']);
    }
}
